﻿@model DotNetMVC.OA.Model.ActionInfo

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>SetRole</title>
    <script src="~/Scripts/jquery.min.js"></script>
    <script type="text/javascript">
        //提交表单
        function submitForm() {
            $.ajax({
                type: 'post',
                url: '/ActionInfo/ProcessSetRole/',
                data: $("form").serialize(),
                success: function (data) {
                    if (data == "ok") {
                        //调用父窗口方法
                        window.parent.window.afterSetRoleSuccess();
                    } else {
                        //错误信息
                        window.parent.window.afterSetRoleError(data);
                    }
                }
            });
        }
    </script>
</head>
<body>
    <h2>当前给用户：@Model.ActionName 设置角色</h2>
    <hr />
    @{
        //所有角色
        List<RoleInfo> AllRoles = ViewBag.AllRoles;
        //用户已有角色
        List<long> existRoleIdList = ViewBag.ExitsRoles;
        <form action="/" method="post">
            <input type="hidden" name="actionId" value="@Model.ID" />
            @{
                int i = 0;
                foreach (var roleInfo in AllRoles)
                {
                    string str = "ckb_" + roleInfo.ID;
                    //3项 换行
                    if (i != 0 && i % 3 == 0)
                    {
                        <hr />
                    }
                    //选中用户已有角色
                    if (existRoleIdList.Contains(roleInfo.ID))
                    {
                        <input type="checkbox" checked="checked" name="@str" id="@str" />
                    }
                    else
                    {
                        <input type="checkbox" name="@str" id="@str" />
                    }
                    <label for="@str">@roleInfo.RoleName</label>
                    i++;
                }
            }
        </form>
    }
</body>
</html>
